package com.xiaolei.library.common;

import android.widget.CompoundButton;

import androidx.annotation.NonNull;

import com.xiaolei.library.R;

/**
 * 系统事件区分监听器
 */
public abstract class OnSystemCheckedChangeListener implements CompoundButton.OnCheckedChangeListener
{
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {
        Object tag = buttonView.getTag(R.id.is_system_event_tag);
        boolean isSystemEvent = tag != null && (boolean) tag;
        buttonView.setTag(R.id.is_system_event_tag, null);
        onChanged(buttonView, isChecked, isSystemEvent);
    }
    
    /**
     * @param buttonView 发生事件的控件
     * @param isChecked  是否是被选中
     * @param sysEvent   是否是系统事件
     */
    public abstract void onChanged(@NonNull CompoundButton buttonView, boolean isChecked, boolean sysEvent);
}
